<?php
namespace App\Modules\Admin\Controllers;

use App\Http\Requests\Admin\AddSysUserRequest;
use App\Http\Resources\Admin\SysUserOptionsResource;
use App\Modules\Admin\Services\UserService;
use Illuminate\Http\Request;
use App\Http\Resources\Admin\SysUserResource;


class UserController extends AdminController
{
    public function index(Request $request, UserService $service)
    {
        $users = SysUserResource::collection($service->page($request->all()));
        $data = [
            'list' => $users,
            'total' => $users->total()
        ];
        return $this->responseSuccess($data);
    }

    public function options(UserService $service)
    {
        return $this->responseSuccess(SysUserOptionsResource::collection($service->options()));
    }

    public function add(AddSysUserRequest $request, UserService $service)
    {
        return $this->responseSuccess($service->add($request->all()));
    }

    public function edit(Request $request, Int $id, UserService $service)
    {
        return $this->responseSuccess($service->edit($id, $request->all()));

    }

    public function detail(Int $id, UserService $service)
    {
        return $this->responseSuccess(new SysUserResource($service->detail($id)));

    }

    public function del(Int|String $id, UserService $service)
    {
        return $this->responseSuccess($service->del($id));
    }

    public function password(Request $request, Int $id, UserService $service)
    {
        return $this->responseSuccess($service->changePassword($id, $request->password));
    }
}